<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width,initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv=X-UA-Compatible content="IE=edge,chrome=1">
    <meta content=always name=referrer>
    <link rel="stylesheet" type="text/css" href="__STATIC__/css/renzheng.css">
    <script src="__STATIC__/js/jquery-1.8.2.js"></script>
    <title>修改登录密码</title>
</head>
<body>
<div class="wrap-pass">
    <div class="header">
        <p>修改登录密码</p>
        <img src="__STATIC__/img/back.png" class="back" onclick =window.location.href="{:url('mobile/shop_set/safety')}";>
    </div>
    <form  method="post" action="" id="form">
    <div class="center">
        <div>
            <input class="text" type="text" placeholder="手机号码" value="{$username}" name="username" readonly>
        </div>
        <div>
            <input class="text" type="text" name="verification" placeholder="验证码">
            <span><a href="javascript:check_num();" id="verif">获取验证码</a></span>
        </div>
        <div>
            <input class="text" type="password" name="password" placeholder="新密码">
        </div>
        <div>
            <input class="text" type="password" name="confirmPassword" placeholder="确认密码">
        </div>
    </div>
    <input type="button" class="submit" onclick="putData()" value="确定">
    </form>
</div>
{include file="public/src" /}
<script>
    //提交检测
    function putData(){
        if ($("[name='verification']").val() == ''){
            layer.open({content:'验证码不能为空',skin:'msg',time:2});
            return false;
        }
        var pwd = $("[name='password']");
        var confPwd = $("[name='confirmPassword']");
        if (pwd.val() == ''){
            layer.open({content:'请输入密码',skin:'msg',time:2});
            return false;
        }
        if (confPwd.val() == ''){
            layer.open({content:'请确认密码',skin:'msg',time:2});
            return false;
        }
        if (pwd.val() != confPwd.val()){
            layer.open({content:'两次输入的密码不一致',skin:'msg',time:2});
            return false;
        }
        $('#form').ajaxSubmit({
            url:"{:url('mobile/shop_set/edit_pwd')}",
            dataType:'json',
            type:'post',
            enctype: 'multipart/form-data',
            success:function(t){
                layer.open({content:t.message,skin:'msg',time:2});
                if (t.code == 200){
                    setTimeout(function () {
                        window.location.href = "safety";
                    },2000);
                }
            }
        })
    }
    //发送验证码
    function check_num(){
        var tel = $("[name='username']").val();
        count_down();
        $.ajax({
            url:'get_code',
            dataType:'json',
            type:'post',
            data:{'tel':tel,'login':'login'},
            success:function(t){
                if (t.code != 200){
                    layer.open({content: t.message,skin: 'msg',time:2});
                }
            },
            error:function () {
                layer.open({content:'网络繁忙,请重试',skin:'msg',time:2});
            }
        })
    }
    //验证码倒计时
    function count_down(){
        var num = 60;
        var verif = $('#verif');
        var timer = setInterval(function(){
            verif.text(num+'秒');
            if (num <=60 && num >= 1){
                verif.removeAttr('href');
            }else{
                verif.text('重新获取验证码');
                window.clearInterval(timer);
                verif.attr("href",'javascript:check_num();');
            }
            num--;
        },1000);
    }

</script>
</body>
</html>